package com.ruoyi.maintenance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.maintenance.domain.DeviceMaintenance;
import com.ruoyi.maintenance.service.IDeviceMaintenanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备维修列表Controller
 * 
 * @author zjt
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/maintenance/maintenance")
public class DeviceMaintenanceController extends BaseController
{
    @Autowired
    private IDeviceMaintenanceService deviceMaintenanceService;

    /**
     * 查询设备维修列表列表
     */
    @PreAuthorize("@ss.hasPermi('maintenance:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceMaintenance deviceMaintenance)
    {
        startPage();
        List<DeviceMaintenance> list = deviceMaintenanceService.selectDeviceMaintenanceList(deviceMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出设备维修列表列表
     */
    @PreAuthorize("@ss.hasPermi('maintenance:maintenance:export')")
    @Log(title = "设备维修列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceMaintenance deviceMaintenance)
    {
        List<DeviceMaintenance> list = deviceMaintenanceService.selectDeviceMaintenanceList(deviceMaintenance);
        ExcelUtil<DeviceMaintenance> util = new ExcelUtil<DeviceMaintenance>(DeviceMaintenance.class);
        util.exportExcel(response, list, "设备维修列表数据");
    }

    /**
     * 获取设备维修列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('maintenance:maintenance:query')")
    @GetMapping(value = "/{maintenanceId}")
    public AjaxResult getInfo(@PathVariable("maintenanceId") Integer maintenanceId)
    {
        return success(deviceMaintenanceService.selectDeviceMaintenanceByMaintenanceId(maintenanceId));
    }

    /**
     * 新增设备维修列表
     */
    @PreAuthorize("@ss.hasPermi('maintenance:maintenance:add')")
    @Log(title = "设备维修列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceMaintenance deviceMaintenance)
    {
        return toAjax(deviceMaintenanceService.insertDeviceMaintenance(deviceMaintenance));
    }

    /**
     * 修改设备维修列表
     */
    @PreAuthorize("@ss.hasPermi('maintenance:maintenance:edit')")
    @Log(title = "设备维修列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceMaintenance deviceMaintenance)
    {
        return toAjax(deviceMaintenanceService.updateDeviceMaintenance(deviceMaintenance));
    }

    /**
     * 删除设备维修列表
     */
    @PreAuthorize("@ss.hasPermi('maintenance:maintenance:remove')")
    @Log(title = "设备维修列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintenanceIds}")
    public AjaxResult remove(@PathVariable Integer[] maintenanceIds)
    {
        return toAjax(deviceMaintenanceService.deleteDeviceMaintenanceByMaintenanceIds(maintenanceIds));
    }
}
